Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incremental version of the solver #1000

Open
wants to merge 17 commits into
base: next
Choose a base branch
from

Conversation

Stevendeo
Copy link
Collaborator

@Stevendeo Stevendeo commented Dec 4, 2023

The target of this PR: the first part before getting rid of the Commands module. As the legacy frontend still relies on it, this PR only cuts all the dependencies of the dolmen loop (solving_loop.ml)

@Stevendeo Stevendeo force-pushed the get-rid-of-cmd branch 5 times, most recently from c27098e to 432d646 Compare December 7, 2023 15:59
@Stevendeo Stevendeo marked this pull request as ready for review December 7, 2023 16:27
@Stevendeo Stevendeo requested review from bclement-ocp, Halbaroth and hra687261 and removed request for bclement-ocp and Halbaroth December 7, 2023 16:28
@@ -1303,7 +1303,7 @@ module Make (Th : Theory.S) : Sat_solver_sig.S = struct

let assume env gf _dep =
(* dep currently not used. No unsat-cores in satML yet *)
assert (SAT.decision_level env.satml == 0);
(* assert (SAT.decision_level env.satml == 0); *)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I commented these assertions because one test failed and I forgot to put them back; the test ./alt-ergo -o smtlib2 --prelude tests/cram.t/prelude.ae tests/cram.t/postlude.smt2 still fails because of it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah because there are push'd level now. We should probably be able to expose the "push level" and check that instead (i.e. assertion that the decision level is equal to the length of the increm_guard). Probably as a SAT.can_assume env.satml check or some such.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be correct not to assert at the decision level 0, but at decision_level env?

Copy link
Collaborator Author

@Stevendeo Stevendeo Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expose the "push level"

Both my solution and yours may be incorrect actually.

(assert f) ; decision level = 0, push level = 0
(push 42) ; decision level = 0, push level = 42
(check-sat)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a counter for every query?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I realized that after (because for the first check-sat it will be 0 as it used to be). The correct test I believe is decision_level <= push_level (to also capture both (check-sat)(push)(check-sat) and (push)(check-sat)(pop)(check-sat)).

Copy link
Collaborator Author

@Stevendeo Stevendeo Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's another solution: at the end of a query, keep track of the current decision level and set it as the latest known decision level on the satml_frontend side. I find it hard to justify keeping the invariant decision_level <= push_level for a consistency check (in other words, if we ever raise this assertion during a pr, I'm not sure how relevant it would be for debugging).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it hard to justify keeping the invariant decision_level <= push_level for a consistency check (in other words, if we ever raise this assertion during a pr, I'm not sure how relevant it would be for debugging).

This is not just a consistency check; I am not sure the solver will do the right thing in this case. In particular, I am not sure the assumed assertions cannot be forgotten upon later backtracking — in fact, I am pretty sure they will be forgotten (partially) for the default CDCL-Tableaux solver given my current understanding of lazy_cnf.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Note that for decisions level between 0 and push_level forgetting assumptions upon backtracking is OK because that is exactly the semantics we want for push and pop)

src/bin/common/solving_loop.ml Outdated Show resolved Hide resolved
tests/cram.t/prelude.ae Show resolved Hide resolved
assert (SAT.decision_level env.satml == 0);
try ignore (assume_aux ~dec_lvl:0 env [add_guard env gf])

try ignore (assume_aux ~dec_lvl:(SAT.decision_level env.satml) env [add_guard env gf])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should benchmark this PR to be sure this modification is ok :)

src/bin/common/solving_loop.ml Outdated Show resolved Hide resolved
src/bin/common/solving_loop.ml Outdated Show resolved Hide resolved
src/bin/common/solving_loop.ml Outdated Show resolved Hide resolved
src/bin/common/solving_loop.ml Outdated Show resolved Hide resolved
src/bin/common/solving_loop.ml Outdated Show resolved Hide resolved
Comment on lines -1640 to -1660
if Options.get_tableaux_cdcl () then
Errors.run_error
(Errors.Unsupported_feature
"Incremental commands are not implemented in \
Tableaux(CDCL) solver ! \
Please use the Tableaux or CDLC SAT solvers instead"
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this was still not working — just commenting here to make sure we don't merge until either this works with Tableaux(CDCL) (probably not worth it, waiting on @Halbaroth investigation whether we should remove Tableaux(CDCL)) or to keep the assert back in.

src/lib/frontend/d_cnf.mli Outdated Show resolved Hide resolved
src/lib/frontend/d_cnf.mli Outdated Show resolved Hide resolved
src/lib/frontend/d_cnf.mli Outdated Show resolved Hide resolved
src/lib/reasoners/fun_sat_frontend.ml Outdated Show resolved Hide resolved
@bclement-ocp
Copy link
Collaborator

Looks like there are conflict, rebase would be appreciated :)

@Stevendeo Stevendeo force-pushed the get-rid-of-cmd branch 3 times, most recently from 21639c6 to 8b80218 Compare December 12, 2023 11:06
@Stevendeo
Copy link
Collaborator Author

I'm not sure why, but the tests do not pass on the CI, but make runtest-ci do work on my side.

@bclement-ocp
Copy link
Collaborator

I'm not sure why, but the tests do not pass on the CI, but make runtest-ci do work on my side.

Weird. I can't reproduce either. But on the CI it seems surprisingly reproducible — all runners on all OSes fail. Maybe a cache problem, somehow?

@Stevendeo
Copy link
Collaborator Author

I'm going to push some commits to this branch to test what's wrong with the tests on the CI, please don't take them into account

@Stevendeo
Copy link
Collaborator Author

Here's the CI's result :

Fatal error: exception File "src/lib/reasoners/satml.ml", line 1990, characters 9-15: Assertion failed

There is no line 1990 in satml.ml...

@Stevendeo Stevendeo force-pushed the get-rid-of-cmd branch 7 times, most recently from 3ba929d to d4cd365 Compare December 14, 2023 10:56
@Stevendeo Stevendeo changed the title WIP: Incremental version of the solver Incremental version of the solver Mar 25, 2024
@Stevendeo Stevendeo marked this pull request as ready for review March 25, 2024 11:07
@Stevendeo Stevendeo marked this pull request as draft March 25, 2024 11:08
@Stevendeo Stevendeo marked this pull request as ready for review March 25, 2024 11:08
@Stevendeo
Copy link
Collaborator Author

Okay I finished working on the pop-reinitialization version. What it does now is to rework all the analysis (removing the smt commands we don't want to be executed twice) when a pop occurs. I will add some documentation to explain what's going on, but at least tests are OK on my machine.

@bclement-ocp
Copy link
Collaborator

What it does now is to rework all the analysis (removing the smt commands we don't want to be executed twice) when a pop occurs

Ah so this uses a stmt list instead of command list? That sounds smart.

@bclement-ocp
Copy link
Collaborator

I will add some documentation to explain what's going on, but at least tests are OK on my machine.

You marked this as ready for review but also noted this; should I wait for that documentation to be written before doing a review or do you want a pass now?

@Stevendeo
Copy link
Collaborator Author

I thought I was ready modulo documentation, but as I wrote documentation I noticed a few issues remaining (cf CI). Ready for review in a minute

@Stevendeo
Copy link
Collaborator Author

Ready! For real this time

Copy link
Collaborator

@bclement-ocp bclement-ocp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a first pass; I will do a second more thorough one later this week but there is still actionable feedback. I wish we had to extract less stuff from D_cnf but oh well.

We need to run benchmarks on both internal datasets (AE format and SMT format) in both modes, will queue them tonight

src/lib/util/options.mli Outdated Show resolved Hide resolved
src/lib/util/options.mli Outdated Show resolved Hide resolved
@@ -999,9 +1004,11 @@ module Make (Th : Theory.S) : SAT_ML with type th = Th.t = struct
let print_aux fmt hc =
Format.fprintf fmt "%a@," Atom.pr_clause hc

let is_unsat env : unit = env.is_unsat <- true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please call this function set_unsat or set_is_unsat :)

src/lib/reasoners/satml.ml Outdated Show resolved Hide resolved
Comment on lines +1045 to +1047
(* This was first added by PR 1000, but it triggers a bug in
tests/cc/testfile-ac_cc002.ae with option
--no-tableaux-cdcl-in-instantiation *)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this code is removed then I believe the unit_tenv_queue field should also be removed (in fact I think it should be removed in any case, it was a quick-and-dirty hack to test an hypothesis if I recall — same goes for this code).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was important to restore the old unit_tenv from before a push (cf Satml.pop)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should only be the case with the code below uncommented — without this code, Alt-Ergo should only ever add to unit_tenv facts that are true at level 0 (otherwise it is probably a soundness bug) which shouldn't be impacted by push/pop.

(If I recall correctly, I added this code and the unit_tenv stack because unit_tenv with the specification of only adding things known at level 0 is less useful with incremental solving and we were trying to solve the performance issues)

src/bin/common/solving_loop.ml Outdated Show resolved Hide resolved
src/bin/common/solving_loop.ml Outdated Show resolved Hide resolved
src/bin/common/solving_loop.ml Outdated Show resolved Hide resolved
src/bin/common/solving_loop.ml Outdated Show resolved Hide resolved
tests/adts/simple_1.ae Show resolved Hide resolved
@Stevendeo
Copy link
Collaborator Author

I can't figure out why there is a test not working on the CI that works on my side. I guess this is because the CI is slow, but I'm not sure where the error is triggered...

@bclement-ocp
Copy link
Collaborator

I can't figure out why there is a test not working on the CI that works on my side. I guess this is because the CI is slow, but I'm not sure where the error is triggered...

The test is testfile-qfbv-timeout.dolmen.smt2 so that is probably because this PR somehow breaks the timelimit-per-goal option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants